<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>过滤器</title>
  </head>
  <body>
    <div id="app">
      <div v-for="item in timearr" :key="item">{{ item | timer }}</div>
    </div>
    <script src="./vue.js"></script>
    <script>
      let app = new Vue({
        el: "#app",
        data: {
          timearr: ["1579657789851", "1563516693000", "1578539380000"],
        },
        filters: {
          timer(value) {
            const date = new Date(+value);
            const year = date.getFullYear();
            const month = date.getMonth() + 1;
            const day = date.getDay();
            const hour = date.getHours();
            const minutes = date.getMinutes();
            const seconds = date.getSeconds();
            return `${year}-${month < 10 ? "0" + month : month}-${
              day < 10 ? "0" + day : day
            } ${hour < 10 ? "0" + hour : hour}:${
              minutes < 10 ? "0" + minutes : minutes
            }:${seconds < 10 ? "0" + seconds : seconds}`;
          },
        },
      });
    </script>
  </body>
</html>
